home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / xachlego < prev    next >
Encoding:
Text File  |  2000-11-17  |  4.9 KB  |  123 lines

  1. #!/usr/app/bin/perl
  2.  
  3. eval 'exec /usr/app/bin/perl  -S $0 ${1+"$@"}'
  4.     if 0; # not running under some shell
  5. # This is (hopefully) a demonstration of how pathetically easy it is to script
  6. # a neato effect you've come up with.  This lil' effect was created by xach,
  7. # and translated by sjburges (me).  You can consider it released under the GPL
  8. # or Artistic liscence, whichever makes you happier.
  9. #
  10. # <Xach> sjburges: 1. pixelize the photo  2. in a new white layer, render a grid
  11. #           at the same resolution as the pixelize, then blur it. threshold the 
  12. #           grid until you get a roundish blob in the center of each square (you
  13. #           may need to repeat a few times).
  14. # <Xach> sjburges: meanwhile, back at the pixelized image, bumpmap it with 
  15. #           itself and a depth of about 5. do this twice. then bumpmap it with 
  16. #           the round blobby layer.
  17. # <Xach> then create a new, clean grid, and bumpmap the pixelized layer with it
  18. #
  19.  
  20. # (To get a decent blobby grid)
  21. # <Xach> <Xach> render a grid at 10x10, gaussian blur at 7, then set levels to 
  22. #           196 1.00 234                                                    
  23.  
  24. # Revision - 1.1:      added a gimp_displays_flush() for 1.0.x users
  25. #                    stopped deleting the layers after removal - it was
  26. #                   causing bad things to happen with refcounts.  I hope
  27. #                   gimp is cleaning up this memory on its own...
  28. #            1.2:   Fixed buggy selection handling - oops ;)  
  29. #            1.3:   Added undo capability by Marc Lehman <pcg@goof.com>
  30. #            1.4:   Marc Lehman <pcg@goof.com>, changed function name
  31. #            1.5:   Seth Burgess <sjburges@gimp.org> added my email, put it
  32. #                   in a directory more suitable than the lame "Misc"
  33. # Here's the boring start of every script...
  34.  
  35. use Gimp qw(:auto __ N_);
  36. use Gimp::Fu;
  37.  
  38. register "xach_blocks",
  39.          "Xach's Blocks o' Fun",
  40.          "Turn your picture into something that resembles a certain trademarked
  41.           building block creation",
  42.          "Seth Burgess",
  43.          "Seth Burgess <sjburges\@gimp.org>",
  44.          "2-15-98",
  45.          N_"<Image>/Filters/Map/Xach Blocks...",
  46.          "*",
  47.          [
  48.           [PF_SLIDER,    "block_size",    "The size of the blocks", 10, [2, 255, 1]],
  49.           [PF_SLIDER,    "knob_factor",    "The size of your knob", 40, [10, 100, 5]],
  50.          ],
  51.          sub {
  52.    my($img,$drawable,$blocksize, $knobfactor)=@_;
  53.      $selection_flag = 0;
  54.         eval { $img->undo_push_group_start };
  55.     if (!$drawable->has_alpha) {
  56.         $drawable->add_alpha;
  57.         }; 
  58.     if ($img->selection_is_empty) {
  59.         $img->selection_all;
  60.         $selection_flag = 1;
  61.         }
  62.     $oldbackground = gimp_palette_get_background();
  63. # Now the fun begins :) 
  64.  
  65.     $selection = $img->selection_save;
  66.   
  67. #1. Pixelize the photo
  68.     $drawable->plug_in_pixelize($blocksize); 
  69. # 2. in a new white layer, render a grid
  70. #           at the same resolution as the pixelize, then blur it.
  71.     $gridlayer = $img->layer_new($img->width, $img->height, RGBA_IMAGE, "Grid 1", 100, 0);
  72.     $img->add_layer($gridlayer,0);
  73.     $img->selection_all;
  74.     gimp_edit_clear($gridlayer);
  75.     gimp_palette_set_background([255,255,255]);
  76.     gimp_edit_fill($gridlayer, BG_IMAGE_FILL);
  77.     $gridlayer->plug_in_grid(1, $blocksize, 0, [0,0,0], 255, 1, $blocksize, 0, [0,0,0], 255, 0, 0, 0, [0,0,0], 0);
  78.     $gridlayer->plug_in_gauss_iir(0.7*$blocksize, 1, 1);
  79.  
  80. #    threshold the 
  81. #   grid until you get a roundish blob in the center of each square (you
  82. #   may need to repeat a few times).    
  83.  
  84.     $gridlayer->levels(0, 196, 234, $knobfactor/100.0 , 0, 255);
  85.  
  86. # <Xach> sjburges: meanwhile, back at the pixelized image, bumpmap it with 
  87. #           itself and a depth of about 5. do this twice.  
  88.     gimp_selection_load($selection);
  89.     $drawable->plug_in_bump_map($drawable, 135, 45, 5, 0, 0, 0, 0, 1, 0, 0);
  90.     $drawable->plug_in_bump_map($drawable, 135, 45, 5, 0, 0, 0, 0, 1, 0, 0);
  91.     $drawable->plug_in_bump_map($gridlayer, 135, 45, 5, 0, 0, 0, 0, 1, 0, 0);
  92.  
  93. # <Xach> then create a new, clean grid, and bumpmap the pixelized layer with it
  94.     $img->selection_all;    
  95.     $cleangrid = $img->layer_new($img->width, $img->height, 
  96.                                  RGBA_IMAGE, "Grid 2", 100, 0);
  97.     $img->add_layer($cleangrid,0);
  98.     gimp_edit_fill($cleangrid, BG_IMAGE_FILL);
  99.     $cleangrid->plug_in_grid(1, $blocksize, 0, [0,0,0], 255, 1, $blocksize, 0, [0,0,0], 255, 0, 0, 0, [0,0,0], 0);
  100.     gimp_selection_load($selection);
  101.     $drawable->plug_in_bump_map($cleangrid, 135, 45, 3, 0, 0, 0, 0, 1, 0, 0);
  102.     $img->selection_all;    
  103.  
  104. # Clean up stuff
  105.  
  106.     $img->remove_layer($cleangrid);
  107. #    $cleangrid->delete;  # Deleting these layers after removal seems to cause
  108.                          # strange problems (I think gimp handles this 
  109.                          # automatically now)
  110.     $img->remove_layer($gridlayer);
  111. #    $gridlayer->delete;
  112.     gimp_selection_load($selection);
  113.     gimp_palette_set_background($oldbackground);
  114.     if ($selection_flag ==1) {
  115.         $img->selection_none;
  116.         }
  117.         eval { $img->undo_push_group_end };
  118.     return ();
  119. };
  120.  
  121. exit main;
  122.  
  123.